package com.starinside.wp.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Binary Wang(https://github.com/binarywang)
 */
public class JsonUtils {
    public static String toJson(Object obj) {
        Gson gson = new GsonBuilder()
            .setPrettyPrinting()
            .create();
        return gson.toJson(obj);
    }

    public  static  String responseJSON(Integer status, String msg ){
        return responseJSON(status, msg, null);
    }

    public  static  String responseJSON(Integer status, String msg, Map data ){
        Map<String,  Object> result = new HashMap<>();
        result.put("status", status);
        result.put("msg", msg);
        result.put("data", data);
        return toJson(result);
    }

}
